#!/bin/bash

#stop swapfiles - this may take a while if they are full
status -n "Disabling ZRAM... "

# disable all zram devices
if command -v zram.sh >/dev/null ;then
  sudo zram.sh stop
fi

sudo rm -rf /zram

status_green "Done"
#now running this command should list no swapfiles: cat /proc/swaps

status "Disabling zram kernel module"
sudo rmmod zram || true

status "Removing zram script and service"
sudo rm -f /usr/bin/zram.sh
sudo systemctl disable zram-swap.service
sudo systemctl disable zram-flush.timer
sudo systemctl disable zram-flush.service
sudo rm -f /etc/systemd/system/zram-swap.service /etc/systemd/system/zram-flush.service /etc/systemd/system/zram-flush.timer

status "Reverting kernel parameters"
sudo rm -f /etc/sysctl.d/zram.conf

if [ -f /usr/sbin/dphys-swapfile ];then
  status "Allowing dphys-swapfile.service to run on boot"
  sudo systemctl unmask dphys-swapfile.service #see /lib/systemd/system/dphys-swapfile.service
  sudo systemctl enable dphys-swapfile.service #see /lib/systemd/system/dphys-swapfile.service
fi

if [ -f /lib/systemd/system/mkswap.service ];then
  status "Allowing mkswap.service to run on boot"
  sudo systemctl unmask mkswap.service #see /lib/systemd/system/mkswap.service
  sudo systemctl enable mkswap.service #see /lib/systemd/system/mkswap.service
fi
